<?php
/**
 * 验证类
 *
 * Created		: 2011-02-16
 * Modified		: 2011-02-16
 * @link	  : http://www.phpfo.com
 * @copyright : [PhpFo.Com] (c) 2010 - 2011
 * @package		: Comment
 * @version		: 0.1.0
 * @author		: Joseph Chen (Jsph.chen@gmail.com)
 */
class Validator {
	public static $regex = array(
		'email' => '~([\w\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)~is',
		'qq'    => '~^[1-9][\d]{4,9}$~is',
		'ids'   => '~^(?:[\d]+\,?)+[\d]+$~is',
	);

	public static $len = array(
		'email' => 50
	);

	public static function validate($var, $type, $allowEmpty=true)
	{
		if ($allowEmpty && empty($var)) {
			return true;
		}
		if (isset(self::$len[$type]) && self::$len[$type]<strlen($var)) {
			return false;
		}
		if (isset(self::$regex[$type])) {
			$ret = preg_match(self::$regex[$type], $var);
		}

		return $ret;
	}

}